<?php 
namespace app\Admin\Controller;

use think\Controller;
use think\Request;


//公共的控制器类
class AdminController extends Controller{

	//初始化的方法
	public function _initialize(){
        //dump(session('admin_user'));die;

		//判断session是否存在
		if(empty(session('admin_user'))){
			//跳转到 登陆页
			$this->redirect("login/login");
		}

		//dump($request->module());die;

		//权限过滤
        $request = Request::instance();
		//获取当前访问的模型，控制器，方法
        $mname = $request->module();
        $cname = $request->controller();
        $aname = $request->action();
        //echo $mname.'/'.$cname.'/'.$aname;

		$nodelist = session('nodelist'); //获取权限列表

		//dump($nodelist);die;
		//让超级管理员admin拥有所有权限
		if(session('admin_user')['username'] != 'admin'){
		    //验证权限
            if(empty($nodelist[$cname]) || !in_array($aname,$nodelist[$cname])){
                //dump($cname);dump($aname);die;
                $this->error("抱歉！没有操作权限！");
                exit;
            }
		}

	}

}
 